package domain;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
public class Registration extends DomainEntity {

	// Constructors

	public Registration() {
		super();
		statusUpdates = new HashSet<StatusUpdate>();
	}

	// Atributes

	private Date registrationDate;
	private Double amountOfWork;

	
	@NotNull
	@Valid
	@Past
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	public Date getRegistrationDate() {
		return registrationDate;
	}

	public void setRegistrationDate(Date registrationDate) {
		this.registrationDate = registrationDate;
	}
	
	
	@Min(0)
	public Double getAmountOfWork() {
		return amountOfWork;
	}

	public void setAmountOfWork(Double amountOfWork) {
		this.amountOfWork = amountOfWork;
	}

	// Relationships

	private Project project;
	private User user;
	private Collection<StatusUpdate> statusUpdates;

	@NotNull
	@Valid
	@ManyToOne(optional = false)
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@NotNull
	@Valid
	@ManyToOne(optional = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@NotNull
	@Valid
	@Cascade(CascadeType.ALL)
	@OneToMany(mappedBy = "registration")
	public Collection<StatusUpdate> getStatusUpdates() {
		return statusUpdates;
	}

	public void setStatusUpdates(List<StatusUpdate> statusUpdates) {
		this.statusUpdates = statusUpdates;
	}
	
	

}
